<template>
  <a-modal title='购销合同信息' v-model='visible' v-if='visible' width='800px' height='500px' @cancel='handleCancel' @ok='handleSubmit'>
    <f-form ref='form' :action='api.hyorder' v-if='visible' :form-key='this.formItem.orderId'>
      <f-form-item label='单位名称' name='customName' disabled :value.sync='formItem.customName' style='width: 600px'/>
      <f-form-item label='收货地址' type='areaSelect' :value='areaIds' :colSpan='5' :level='3' :required='true' name='areaIds'  @change='areaSelectChange'></f-form-item>
      <f-form-item label='付款方式' name='payTypeValue' type='radio' :data='payType' :value.sync='payTypeValue'/>
      <f-form-item label='付款期限' name='dayNum' v-if='payTypeValue=="2"' data-type='num' :value.sync='dayNum' style='width:600px' suffix="RMB"/>
      <f-form-item label='运输方式' name='transportTypeValue' type='radio' :data='transportType' :value.sync='transportTypeValue' />
      <f-form-item label='其他方式' name='otherTransportTypeValue' :value.sync='otherTransportTypeValue' v-if='transportTypeValue=="4"' />
    </f-form>
  </a-modal>
</template>
<script>
import api from "../../js/api"

export default {
  name: "GxhtModal",
  props: {},
  data() {
    return {
      refs: this.$refs,
      api: Object.assign(api, this.api),
      loading: false,
      visible: false,
      isAdd: true,//是否是添加模式
      loaded: false,//是否加载完成
      areaIds: [],
      transportTypeValue: "1",
      payTypeValue: "2",
      otherTransportTypeValue:"",
      dayNum: 60,
      payType: [{ label: "电汇", value: "1" }, { label: "货到付款", value: "2" }],
      transportType: [{ label: "公路", value: "1" }, { label: "铁路", value: "2" }, { label: "航空", value: "3" }, { label: "其他方式", value: "4" }],
      formItem: this.getFormItem(),
      queryParam: {}
    }
  },

  methods: {
    getFormItem() {
      return {
        customAddress: "",
        payType: 1,
        transportType: 1
      }
    },
    open(record) {
      this.payTypeValue="2";
      this.transportTypeValue="1";
      this.otherTransportTypeValue="";
      this.dayNum=60;
      this.areaIds=[]
      if (record) {
        this.http.get(this, {
          url: this.api.hyorder.get,
          data: {
            orderId: record.orderId,
            handlerName: "hyOrderGxhtGetHandler"
          },
          success: function(me, data) {
            me.formItem = data
            me.visible = true
            me.loaded = true
          }
        })
      }
      this.visible = true
    },
    areaSelectChange(value){
      this.areaIds=value;
    },
    /**
     * 下载购销合同
     * @param record
     */
    downloadGxht(params) {
      let env = process.env.NODE_ENV
      let url = "bus/export/gxht"
      if (env == "development") {
        url = "../../../base/bus/export/gxht"
      }
      this.http.exportExcel(this, {
        url: url,
        data: params,
        success: function(me, data) {
          me.close()
        }
      })
      this.visible = false
    },
    close() {
      this.$emit("close")
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
    handleSubmit() {
      this.downloadGxht({
        orderId: this.formItem.orderId,
        proId:this.areaIds[0],
        cityId:this.areaIds[1],
        areaId:this.areaIds[2],
        payTypeValue:this.payTypeValue,
        transportTypeValue:this.transportTypeValue,
        transportValue:this.transportValue,
        otherTransportTypeValue:this.otherTransportTypeValue,
        dayNum:this.dayNum
       
      })
    }
  },
  created() {
  },
  components: {}
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
